<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="../jsLib/angular.js"></script>
    <title></title>
</head>
<body>
<div  ng-app="myApp" ng-controller="myCrol">
    <p>{{user.name}}</p>
    <button  ng-click="aa()">aa</button>
    <button  ng-click="bb()">bb</button>
</div>
<script>
    var app = new angular.module('myApp',[]);
    app.controller('myCrol',function($scope,$http,$timeout){
        console.log($http);
//        $scope.watch($scope.user.name);
        $scope.user={name:"原来的"}

        $scope.aa = function(){
            /*    var   url= '../php/test.php';
             var request = new XMLHttpRequest();
             var  myRandom  = parseInt(Math.random()*10000);
             request.open('POST',url);
             request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
             request.onreadystatechange =function(){
             if(request.readyState==4){
             if(request.status==200){
             $scope.user.name = request.responseText;
             return  $scope.user.name
             //                        div[0].innerHTML = request.responseText;
             }
             }
             }
             request.send("age=bill");*/
            var   url= '../php/test.php';

            $http.get(url).success(function(response) {  $scope.user.name = response;});

        }
        $scope.bb = function(){
                setTimeout(function(){
             $scope.user.name="timeout"
             alert( $scope.user.name)
             },1000)
        }
    })
</script>
</body>
</html>